package work.huangxin.share.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import work.huangxin.share.domain.schedule.CampusInfo;
import work.huangxin.share.service.CampusInfoService;
import work.huangxin.share.service.impl.MinioSysFileServiceImpl;
import work.huangxin.share.util.status.BaseResponse;
import work.huangxin.share.util.status.CodeEnum;
import work.huangxin.share.util.status.ResponseData;

/**
 * @author 季台星
 * @Date 2023 04 28 15 13
 */
@RestController
@RequestMapping("/wx/admin/api/campus")
public class AdminCampusController {
    @Autowired
    private CampusInfoService campusInfoService;
    @GetMapping("/list")
    public BaseResponse getCampusList(@RequestParam("pageNo") Integer pageNo,
                                      @RequestParam("pageSize") Integer pageSize){
        return ResponseData.success(campusInfoService.getCampusInfoListByPage(pageNo,pageSize));
    }
    @PostMapping("/add")
    public BaseResponse addCampusInfo(@RequestBody CampusInfo campusInfo){
        if (null == campusInfo.getId()){
            return ResponseData.error(CodeEnum.NOT_FOUND);
        }
        int status = campusInfoService.addCampusById(campusInfo);
        return status > 0 ? ResponseData.success() : ResponseData.error(CodeEnum.BODY_NOT_MATCH);
    }
    @PostMapping("/delete/{id}")
    public BaseResponse deleteCampusInfo(@PathVariable Integer id){
        int status = campusInfoService.deletedCampusInfo(id);
        return status > 0 ? ResponseData.success() : ResponseData.error(CodeEnum.BODY_NOT_MATCH);
    }
    @PostMapping("/update")
    public BaseResponse updateCampusInfo(@RequestBody CampusInfo campusInfo){
        if (null == campusInfo.getId()){
            return ResponseData.error(CodeEnum.NOT_FOUND);
        }
        int status = campusInfoService.updateByPrimaryKey(campusInfo);
        return status > 0 ? ResponseData.success() : ResponseData.error(CodeEnum.BODY_NOT_MATCH);
    }
}
